package cn.tedu;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Demo04 {
    public static void main(String[] args) {
        //获取连接
        try (
                Connection conn = DBUtils.getConn()
                ){

            Statement s = conn.createStatement();
            ResultSet rs = s.executeQuery("select name,sal from emp");
            while (rs.next()){
                //通过字段名获取位置
//                String name = rs.getString("name");
                //通过字段的位置获取数据
                String name = rs.getString(1);
                double sal = rs.getDouble(2);
                System.out.println(name+":"+sal);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
